var id = $("#id").val();
/*
 * @Description: 预加载
 * @param : 
 */
$(function (){
	for(var x=0;x<5;x++){
		var deliveryUnit = "",date = "",receivingWarehouse = "",number = "",orderNumber = "";
		var oddNumbers = "",code = "",name = "",spec = "",unit = "",num = "",materialWaste = "",industrialWaste = "",remarks = "";
		var summary = "",auditor = "",bookkeeper = "",acceptor = "",storekeeper = "",documentMaker = "";
		var content = "";
		content = "<div>";
		content += 	"<div class='heading'><span>中意马达成品（半成品）完工入库单</span></div>";
		content += 	"<div class='content'>";
		content +=		"<span class='info'>交货单位：</span><span class='contentS' style='width:10%;'>"+ deliveryUnit +"</span>";
		content +=		"<span class='info'>日期：</span><span class='contentS' style='width:10%;'>"+ date +"</span>";
		content +=		"<span class='info'>收货仓库：</span><span class='contentS' style='width:15%;'>"+ receivingWarehouse +"</span>";
		content +=		"<span class='info'>编号：</span><span class='contentS' style='width:10%;'>"+ number +"</span>";
		content +=		"<span class='info'>销售订单号：</span><span class='contentS' style='width:12%;'>"+ orderNumber +"</span>";
		content +=	"</div>";
		content +="</div>";
		content += "<table class='listTable'>";
		content += 	"<tr><th style=''>源单单号</th><th style='width:20%;'>物料编码</th><th>物料名称</th><th style='width:15%;'>规格型号</th><th style=''>单位</th><th style=''>数量</th><th style=''>料废</th><th style=''>工废</th><th style='width:15%;'>备注</th></tr>";
		content += 	"<tr><td>"+ oddNumbers +"</td><td class='left'>"+ code +"</td><td>"+ name +"</td><td class='left'>"+ spec +"</td><td>"+ unit +"</td><td>"+ num +"</td><td>"+ materialWaste +"</td><td>"+ industrialWaste +"</td><td>"+ remarks +"</td></tr>";
		content +="</table>";
		content += "<div>";
		content +=		"<div class='content'>";
		content +=			"<span class='info'>销售摘要：</span><span class='contentS' style='width: 90%;'>" + summary + "</span>";
		content +=		"</div>";
		content +=		"<div class='content'>";
		content +=			"<span class='info'>审核：</span><span class='contentS personContent'>" + auditor + "</span>";
		content +=			"<span class='info'>记账：</span><span class='contentS personContent'>" + bookkeeper + "</span>";
		content +=			"<span class='info'>验收：</span><span class='contentS personContent'>" + acceptor + "</span>";
		content +=			"<span class='info'>保管：</span><span class='contentS personContent'>" + storekeeper + "</span>";
		content +=			"<span class='info'>制单：</span><span class='contentS personContent'>" + documentMaker + "</span>";
		content +=		"</div>";
		content +="</div>";
		$(".rowContent").append("<div class='row'>" + content + "</div>");
	}
/*	var head = "<tr><th style=''>源单单号</th><th style='width:20%;'>物料编码</th><th>物料名称</th><th style='width:15%;'>规格型号</th><th style=''>单位</th><th style=''>数量</th><th style=''>料废</th><th style=''>工废</th><th style='width:15%;'>备注</th></tr>";
	var body = "";
	for(var x=0;x<5;x++){
		var oddNumbers = "",code = "",name = "",spec = "",unit = "",
		num = "",materialWaste = "",industrialWaste = "",remarks = "";
//		body +="<tr><td>"+ data.rows[x].fOperSN +"</td><td>" + data.rows[x].fOperName + "</td><td class='left'>" + data.rows[x].fNote +"</td><td>"+ data.rows[x].fTranOutQty +"</td></tr>";
//		body +="<tr><td>WORK2018050" + x + "</td><td class='left'>5.05.01.ZBM3/160-F-B2-K1Y</td><td>带制动器液压马达</td><td class='left'>ZBM3/160-F-B2-K1Y</td><td>台</td><td>"+ x*10000 +"</td><td></td><td></td><td></td></tr>";
		for(var y=x;y<2;y++){
			oddNumbers = "WORK2018050" + y;
			code = "5.05.01.ZBM3/160-F-B2-K1Y" + y;
			name = "带制动器液压马达" + y;
			spec = "ZBM3/160-F-B2-K1Y" + y;
			unit = "台";
			num = 100 * y;
			materialWaste = "";
			industrialWaste = "";
			remarks = "";
			break;
		}
		body +="<tr><td>"+ oddNumbers +"</td><td class='left'>"+ code +"</td><td>"+ name +"</td><td class='left'>"+ spec +"</td><td>"+ unit +"</td><td>"+ num +"</td><td>"+ materialWaste +"</td><td>"+ industrialWaste +"</td><td>"+ remarks +"</td></tr>";
	}
	$("#listTable").html(head+body);
	
	$("#deliveryUnit").text("转向器车间");
	$("#date").text("2019-08-11");
	$("#receivingWarehouse").text("外贸订单成品库");
	$("#number").text("CIN142369");
	$("#orderNumber").text("SEORD080481");
	
	var summary = "";
	var auditor = "";
	var bookkeeper = "";
	var acceptor = "";
	var storekeeper = "";
	var documentMaker = "";
	$("#summary").text("1.土耳其丹尼斯2.土耳其丹尼斯HYDRO-WORK标牌 打后面客户型号。3.普通出口纸箱。1.土耳其丹尼斯2.土耳其丹尼斯HYDRO-WORK标牌 打后面客户型号。3.普通出口纸箱");
	$("#auditor").text("邓昌鹏(普通车床)");
	$("#bookkeeper").text("邓昌鹏(普通车床)");
	$("#acceptor").text("邓昌鹏(普通车床)");
	$("#storekeeper").text("邓昌鹏(普通车床)");
	$("#documentMaker").text("邓昌鹏(普通车床)");*/
	$.ajax({
		url:pathUrl("subcout/getSubcout.action"),
		type:'POST',
		dataType:'JSON',
		async : false,
		data:{'id' : id},
		success:function(data){
//			console.log(data)
/*			var deliveryUnit = "",date = "",receivingWarehouse = "",number = "",orderNumber = "";
			var oddNumbers = "",code = "",name = "",spec = "",unit = "",num = "",materialWaste = "",industrialWaste = "",remarks = "";
			var summary = "",auditor = "",bookkeeper = "",acceptor = "",storekeeper = "",documentMaker = "";
			var content = "";
			content = "<div>";
			content += 	"<div class='heading'><span>中意马达成品（半成品）完工入库单</span></div>";
			content += 	"<div class='content'>";
			content +=		"<span class='info'>交货单位：</span><span class='contentS' style='width:10%;'>"+ deliveryUnit +"</span>";
			content +=		"<span class='info'>日期：</span><span class='contentS' style='width:10%;'>"+ date +"</span>";
			content +=		"<span class='info'>收货仓库：</span><span class='contentS' style='width:15%;'>"+ receivingWarehouse +"</span>";
			content +=		"<span class='info'>编号：</span><span class='contentS' style='width:10%;'>"+ number +"</span>";
			content +=		"<span class='info'>销售订单号：</span><span class='contentS' style='width:12%;'>"+ orderNumber +"</span>";
			content +=	"</div>";
			content +="</div>";
			content += "<table class='listTable'>";
			content += 	"<tr><th style=''>源单单号</th><th style='width:20%;'>物料编码</th><th>物料名称</th><th style='width:15%;'>规格型号</th><th style=''>单位</th><th style=''>数量</th><th style=''>料废</th><th style=''>工废</th><th style='width:15%;'>备注</th></tr>";
			content += 	"<tr><td>"+ oddNumbers +"</td><td class='left'>"+ code +"</td><td>"+ name +"</td><td class='left'>"+ spec +"</td><td>"+ unit +"</td><td>"+ num +"</td><td>"+ materialWaste +"</td><td>"+ industrialWaste +"</td><td>"+ remarks +"</td></tr>";
			content +="</table>";
			content += "<div>";
			content +=		"<div class='content'>";
			content +=			"<span class='info'>销售摘要：</span><span class='contentS' style='width: 90%;'>" + summary + "</span>";
			content +=		"</div>";
			content +=		"<div class='content'>";
			content +=			"<span class='info'>审核：</span><span class='contentS personContent'>" + auditor + "</span>";
			content +=			"<span class='info'>记账：</span><span class='contentS personContent'>" + bookkeeper + "</span>";
			content +=			"<span class='info'>验收：</span><span class='contentS personContent'>" + acceptor + "</span>";
			content +=			"<span class='info'>保管：</span><span class='contentS personContent'>" + storekeeper + "</span>";
			content +=			"<span class='info'>制单：</span><span class='contentS personContent'>" + documentMaker + "</span>";
			content +=		"</div>";
			content +="</div>";
			$(".rowContent").append("<div class='row'>" + content + "</div>");*/
			var str = "",title;
			var dataNew = data.rows[0];
			str = toUtf8(dataNew.fInterId+"");
			var key, value;
			for (x in dataNew) {//往span里写值
				key = x;
				value = dataNew[x] == null?"":dataNew[x];
				if(x == 'fFetchDate'){
					value = dateFormatter(dataNew[x]);
				}
				$("#"+key).text(value);
			}

			$("#qrcode").qrcode({
				width: 100,
				height: 100,
				correctLevel : 3,
				text: str
			});
		}
	});
	setTimeout(function(){
		print();
	}, 500);
});

/*
 * @Description: 打印
 * @param :
 */
function print() {
	var canvas=document.getElementsByTagName("canvas")[0];
	var dataURL = canvas.toDataURL("image/png");
	var img = '<img src="'+dataURL+'"></img>';
	$("#qrcode").html(img);
	$(".rowContent").print({
		deferred: $.Deferred().done(function() { window.close(); })//打印完后自动关闭打印页面
	});
}